﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HexEditor_
{
    public class ConsoleProgram
    {
        public List<ConsoleInputMode> ModeList { get; set; }
        public ConsoleEditView Viewer;
        public HexEditor Editor;

        public bool Initialize()
        {
            ModeList = new List<ConsoleInputMode>();
            ModeList.Add(new CommandMode());

            Editor = new HexEditor();
            Editor.Initialize(true);

            Viewer = new ConsoleEditView();
            Viewer.SetDoc(this, Editor);

            return true;
        }
        public ConsoleInputMode GetCurrentMode()
        {
            if (ModeList.Count > 0)
                return ModeList[ModeList.Count - 1];
            return null;
        }
        public void Run()
        {
            while (ModeList.Count > 0)
            {
                ConsoleKeyInfo key = Console.ReadKey(true);
                if (ModeList[ModeList.Count - 1].OnGetKey(this, key))
                {
                    ModeList.RemoveAt(ModeList.Count - 1);
                }
            }
        }
    }
}
